package com.dxy.lc.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Value("${core.web.allowedOrigins:*}")
    private String allowedOrigins;
    @Value("${core.web.allowedMethods:*}")
    private String allowedMethods;
    @Value("${core.web.allowedHeaders:*}")
    private String allowedHeaders;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins(this.allowedOrigins.split(","))
                .allowedMethods(this.allowedMethods.split(","))
                .allowedHeaders(this.allowedHeaders.split(","));

    }
}
